package com.example.dao;

import com.example.model.Book;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface BookDao {
    @Select("select * from book")
    List<Book> getAllBooks();

    @Select("select * from book where id = #{id}")
    Book getBookById(@Param("id") int id);

    @Insert("insert into book (id,name,author,publisher,price) values (#{book.id},#{book.name},#{book.author},#{book.publisher},#{book.price})")
    void addBook(@Param("book") Book book);

    @Update("update book set name = #{book.name},author = #{book.author},publisher = #{book.publisher},price = #{book.price} where id = #{book.id}")
    void updateBook(@Param("book")Book book);

    @Delete("delete from book where id = #{id}")
    void deleteBook(@Param("id") int id);
}
